Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create commerce context #8

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

adamsokolowski06
Copy link
Collaborator

References

Changed

I wonder if it makes sense to break CommerceContext into even more, entity-based contexts like ProductContext, PromotionContext, OrderContext (I guess there might be one in the future), let me know.

Visuals

None

How can this be validated?

  1. Use the CommerceContext in behat config file
  2. Prepare a test using some of these steps
  3. Run behat tests

Pull request checklist

  • Can be deploy automatically? If manual actions are required: did you describe the deploy steps?
  • Is the documentation updated, if it makes sense?
  • Are necessary translations added/updated?
  • Did you update sanitization routines, where personal information is handled?

.github/assets/phpstan.neon Outdated Show resolved Hide resolved
*
* @var array
*/
protected $promotions = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about instead we just create an abstract base class, that cleans up something like "entities"?

src/CommerceContext.php Outdated Show resolved Hide resolved
* @Then I remove promotions :titles
*/
public function iRemovePromotions($titles) {
$promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could move this into a base class as well, and also pass the entity type id as a parameter?

src/CommerceContext.php Show resolved Hide resolved
@adamsokolowski06
Copy link
Collaborator Author

adamsokolowski06 commented Oct 9, 2024

Regarding the failing tests, either there's a bug or I don't know the alphabet 😬
EDIT: Nevermind, new rules have been introduced

* Create coupon.
*/
public function couponCreate($coupon) {
$saved = $this->getDriver()->createEntity('commerce_promotion_coupon', $coupon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this make them automatically deleted after the scenario?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm pretty sure of that. I checked the db records for commerce_promotion_coupon get cleared after a scenario with creating coupons

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now 100% sure that is not the case.

The entities are probably randomly deleted only because they are tied to a promotion deleted in the same cleanup. But there is nothing in our test classes or drupal extension to clean it up. We should do that here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be as easy as append it to $this->entities though

* Create coupon.
*/
public function couponCreate($coupon) {
$saved = $this->getDriver()->createEntity('commerce_promotion_coupon', $coupon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now 100% sure that is not the case.

The entities are probably randomly deleted only because they are tied to a promotion deleted in the same cleanup. But there is nothing in our test classes or drupal extension to clean it up. We should do that here

* Create coupon.
*/
public function couponCreate($coupon) {
$saved = $this->getDriver()->createEntity('commerce_promotion_coupon', $coupon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be as easy as append it to $this->entities though

* @AfterScenario
*/
public function cleanExchangeRates() {
$database = \Drupal::database();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to either be wrapped in some conditional to check if the database table exists or wrapped in try/catch. This is not default commerce, and can be disabled on sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants